package test01;

import java.util.ArrayList;
import java.util.List;

// 求子集
public class Test_Solution {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4};
        System.out.println(subsets(arr));
    }
    static List<List<Integer>> res = new ArrayList<List<Integer>>();
    static List<Integer> list = new ArrayList<>();

    public static List<List<Integer>> subsets(int[] nums) {

        res.add(new ArrayList<>());
        dfs(nums,0);
        return res;
    }

    public static void  dfs(int[] nums, int start) {
        if(start >= nums.length) return;

        for(int i= start;i<nums.length;i++) {
            list.add(nums[i]);
            res.add(new ArrayList<Integer>(list));
            dfs(nums,i+1);
            list.remove(list.size()-1);
        }
//        System.out.println(list);
    }
}
